Skip to content

Conversation

arrestle
Copy link
Contributor

@arrestle arrestle commented Sep 23, 2025

Description

  • [AAP-52229] Platform RBAC actions not being logged in AAP-UI Activity Stream
  • What is being changed? Enhanced RoleUserAssignment and RoleTeamAssignment models in django-ansible-base to inherit from AuditableModel
  • Why is this change needed? Platform RBAC actions (role assignments) are not being logged in AAP-UI Activity Stream, breaking audit trails for compliance and security oversight
  • How does this change address the issue? Adding AuditableModel inheritance enables automatic activity stream logging for all role assignments, providing complete audit trails showing "who assigned what role to whom when"

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Test update
  • Refactoring (no functional changes)
  • Development environment change
  • Configuration change

Self-Review Checklist

  • I have performed a self-review of my code
  • I have added relevant comments to complex code sections
  • I have updated documentation where needed
  • I have considered the security impact of these changes
  • I have considered performance implications
  • I have thought about error handling and edge cases
  • I have tested the changes in my local environment

Testing Instructions

  • Create role assignment in test_app and check activity stream entries
  • Run: tox -e py -- test_app/tests/rbac/test_rbac_activity_stream.py

Expected Results

  • Both CREATE and DELETE user and team role assignment operations are properly logged

Additional Context

aap-gateway test pr#1011

@arrestle arrestle marked this pull request as draft September 23, 2025 22:02
@arrestle arrestle changed the title [AAP--52229] Add AuditableModel inheritance to RBAC assignment models [AAP-52229] Add AuditableModel inheritance to RBAC assignment models Sep 24, 2025
@arrestle arrestle force-pushed the aap-52229-activity-stream branch 6 times, most recently from 188637b to 2b2b0e0 Compare September 24, 2025 22:31
@arrestle arrestle force-pushed the aap-52229-activity-stream branch from f365373 to 3ee0c76 Compare September 24, 2025 22:41
- Add conditional AuditableModel inheritance to RoleUserAssignment and RoleTeamAssignment
- Create DummyAuditableModel for services without activitystream app
- Add comprehensive tests for activity stream functionality and dummy model interface
- Exclude object_role field from activity stream logging
- Enhance activity entry display for role assignments
@arrestle arrestle force-pushed the aap-52229-activity-stream branch from 535bb88 to 7d5432e Compare September 25, 2025 00:18
@arrestle arrestle marked this pull request as ready for review September 25, 2025 01:08
@AlanCoding
Copy link
Member

I don't know what's up with checks, docker image pull mirror.gcr.io/library/postgres:15 works for me locally.

if self.content_type and self.content_type.model.lower() in ['roleuserassignment', 'roleteamassignment']:
operation_text = self.get_operation_display()
created_by_text = str(self.created_by) if self.created_by else "Unknown"
return f'[{self.created}] Role assignment {operation_text.lower()} by {created_by_text}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree a custom string would make sense because "roleuserassignment" is verbose. But I would question whether we could solve this generally by using _meta.verbose_name.title() instead? Because "Role assignment" drops the user/team designation, which could be useful. This also appears to drop the object_id. I don't think content_type (as a string) was ever useful but it dropped that too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could drop the object_id, but you would want to replace it by like self.content_object.object_id, which yeah, is confusing. That's the target object of the assignment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this and decided that if there were any additional assignments implemented in the future they might not necessarily want to be tracked, that decision should be up the PM and the Developer. This code is here to prevent unwanted side-effects.

note There are lots of ways to handle this, such as an attribute on the class

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion here is that we try to make AuditableModel just a normal python class, and not a Django abstract model at all. That way, it can be "seen" and imported by thing not even using Django. You could even move to ansible_base.lib and have the activitystream app import it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but since I was asked to move the ticket back into the backlog by John let's take this up on the Thursday Ansible Staff Engineering Weekly Late -- unless you have a better meeting?

Copy link

github-actions bot commented Oct 2, 2025

DVCS PR Check Results:

PR appears valid (JIRA key(s) found)

Copy link

sonarqubecloud bot commented Oct 2, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants